package com.example.smartcitymovie.ui.movie;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.example.smartcitymovie.MyApplication;
import com.example.smartcitymovie.R;
import com.example.smartcitymovie.bean.PreviewMovieBean;
import com.example.smartcitymovie.bean.PreviewMovieListBean;
import com.example.smartcitymovie.bean.PreviewMoviewMessageBean;
import com.example.smartcitymovie.databinding.ActivityPreviewMovie2Binding;
import com.example.smartcitymovie.databinding.ActivityPreviewMovieBinding;
import com.example.smartcitymovie.utils.OkHttpUtils;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class PreviewMovie extends AppCompatActivity {

    ActivityPreviewMovie2Binding binding;
    private int id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityPreviewMovie2Binding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        getSupportActionBar().setTitle("预告详情");
        id=getIntent().getIntExtra("id",0);
        initView();
    }

    private void initView() {
        OkHttpUtils.getCall("/prod-api/api/movie/film/preview/"+id).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                PreviewMoviewMessageBean previewMoviewMessageBean = MyApplication.getGson().fromJson(response.body().string(),PreviewMoviewMessageBean.class);
                if (previewMoviewMessageBean.getCode()==200){
                   runOnUiThread(new Runnable() {
                       @Override
                       public void run() {
                           binding.TVPreviewMovieName.setText(previewMoviewMessageBean.getData().getName());
                           binding.videoView.setVideoPath(OkHttpUtils.BaseUrl+previewMoviewMessageBean.getData().getVideo());
                           binding.videoView.start();
                       }
                   });
                }
            }
        });
    }
}